import { Toast } from "vant"
import {
    register
} from "@/request/register-request"

export const useRegister = async (show,qqAccount,nickName) => {
    show.value = true;
    try{
        const qq_account = qqAccount.value;
        const nick_name = nickName.value;
        if(!qq_account || qq_account.length <= 0 || qq_account === "" || !nick_name || nick_name.length <= 0 || nick_name === ""){
            Toast("昵称或QQ号均不能为空")
            show.value = false;
        }else{
            const result = await register(qq_account,nick_name);
            if(result.code === 201 && result.message === "success"){
                Toast("注册成功,可以去登录了");
            }else{
                Toast(result.message)
            }
            show.value = false;
        }
    }catch(error){
        Toast("发生错误，错误信息：" + error.message);
    }
}